﻿@{
    ViewBag.Title = "订单管理";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script src="~/Content/js/datepicker/WdatePicker.js"></script>
<script>
    var type = -3;
    $(function () {

        gridList(-3);
        $('#ulOrder a').click(function (e) {
            type = $(this).attr("type");
            $("#btn_search").click();
        });
    });
    function gridList(t) {
        type = t;
        var $gridList = $("#gridList");
        var postData = {
            Type: type,
            OrderCode: $("#txt_keyword").val(),
            Consignee: $("#txt_rName").val(),
            OrderTimeStart: $("#txt_startDate").val(),
            OrderTimeEnd: $("#txt_endDate").val()
        };
        $gridList.dataGrid({
            url: "/ProductManage/Order/GetGridJson_admin",
            postData: postData,
            height: $(window).height() - 128,
            multiselect: false,
            colModel: [
                { label: '主键', name: 'F_Id', hidden: true },
                { label: '订单号', name: 'F_OrderCode', width: 150, align: 'center' },
                { label: '收货人', name: 'F_Consignee', width: 100, align: 'center' },
                 {
                     label: '联系电话', name: 'F_ContactNumber', width: 80, align: 'center'
                 },
                {
                    label: '收货地址', name: 'F_Address', width: 150, align: 'left'
                },
                {
                    label: '订单总额(元)', name: 'F_TotalMoney', width: 100, align: 'center',
                    formatter: function (cellvalue, options, rowObject) {
                        return cellvalue == null ? "" : parseFloat(cellvalue).toFixed(2);
                    }
                },
                {
                    label: '支付方式',
                    name: 'F_IsUseIntegral',
                    width: 60,
                    align: 'center',
                    sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue) {
                            return "积分";
                        }
                        else {
                            return "现金";
                        }
                    }
                },
                {
                    label: '实际支付(元)', name: 'F_ProductPrice', width: 100, align: 'center',
                    formatter: function (cellvalue, options, rowObject) {
                        return cellvalue == null ? "" : parseFloat(cellvalue).toFixed(2);
                    }
                },
                //{ label: '中转中心', name: 'TransferCenterName', width: 100, align: 'center' },
                {
                    label: '下单日期', name: 'F_OrderTime', width: 160, align: 'center'
                },
                {
                    label: '备注', name: 'F_Remark', width: 200, align: 'left'
                }, {
                    label: '订单状态',
                    name: 'F_OrderStatus',
                    width: 100,
                    align: 'center',
                    sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case 0:
                                return "待处理";
                                break;
                            case 1:
                                return "<span style='color:green;'>已支付</span>";
                                break;
                            case 2:
                                return "<span style='color:blue;'>已发货</span>";
                                break;
                            case 3:
                                return "<span style='color:blue;'>已完成</span>";
                                break;
                            case -1:
                                return "<span style='color:red;'>已取消</span>"
                                break;
                            case -2:
                                return "<span style='color:red;'>已作废</span>"
                                break;
                            default:
                                return "--";
                                break;
                        }
                    }
                },
    {
        label: '订单操作',
        name: '',
        width: 200,
        align: 'left',
        sortable: false,
        formatter: function (cellvalue, options, rowObject) {
            var str = "<a href='#' onclick='javascript:btn_details(\"" +
                rowObject.F_Id +
                "\"\,\"" +
                rowObject.F_OrderCode +
                "\")' style='text-decoration:underline;color:blue'>查看</a>";

            if (rowObject.F_OrderStatus == 0) {
                str += " | <a href='#' onclick='javascript:btn_update(\"" +
                    rowObject.F_Id +
                    "\"\,\"" +
                    rowObject.F_OrderCode +
                    "\")' style='text-decoration:underline;color:blue'>订单修改</a>";

                str += " | <a href='#' onclick='javascript:btn_zhf(\"" +
                    rowObject.F_Id +
                    "\"\,\"" +
                    1 +
                    "\")' style='text-decoration:underline;color:blue'>确认支付</a>";

                str += " | <a href='#' onclick='javascript:btn_zf(\"" +
                    rowObject.F_Id + "\")' style='text-decoration:underline;color:blue'>订单作废</a>";
            }
            else if (rowObject.F_OrderStatus == 1) {
                str += " | <a href='#' onclick='javascript:btn_fh(\"" +
                  rowObject.F_Id +
                  "\"\,\"" +
                  2 +
                  "\")' style='text-decoration:underline;color:red'>发货</a>";
            }
            else if (rowObject.F_OrderStatus == 2) {
                str += " | <a href='#' onclick='javascript:btn_zhf(\"" +
                    rowObject.F_Id +
                    "\"\,\"" +
                    3 +
                    "\")' style='text-decoration:underline;color:blue'>确认完成</a>";

            }
            return str;
        }
    }
            ],
            pager: "#gridPager",
            sortname: 'F_OrderTime desc',
            viewrecords: true
        });
        $("#btn_search").click(function () {
            var postData = {
                Type: type,
                OrderCode: $("#txt_keyword").val(),
                Consignee: $("#txt_rName").val(),
                OrderTimeStart: $("#txt_startDate").val(),
                OrderTimeEnd: $("#txt_endDate").val(),
            };
            $gridList.jqGrid('setGridParam', {
                postData: postData
            }).trigger('reloadGrid');
        });
    }
    //查看详情
    function btn_details(Id, code) {
        $.modalOpen({
            id: "Details",
            title: "订单【" + code + "】的详细信息",
            url: "/ProductManage/Order/SetFH?Id=" + Id,
            width: "700px",
            height: "450px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_update(Id, code) {
        $.modalOpen({
            id: "Details",
            title: "订单【" + code + "】的详细信息",
            url: "/ProductManage/Order/Update?orderId=" + Id,
            width: "700px",
            height: "450px",
            btn: null
        });
    }
    function btn_fh(Id, code) {
        $.modalOpen({
            id: "SetFH",
            title: "准备发货",
            url: "/ProductManage/Order/SetFH?Id="+Id,
            width: "950px",
            height: "500px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }

    //处理订单
    function btn_zhf(Id, state) {
        var content = "";
        if (state == "1") {
            $(".jqgrow").each(function (index) {
                var tds = $(this).find("td");
                if (tds.eq(1).text() == Id) {
                    content += "请确认会员【" + tds.eq(3).text() + "】已经支付订单【" + tds.eq(2).text() + "】的<span style='color:red'>【" + tds.eq(7).text() + "】</span>元！";
                    return;
                }
            });
            if (content != "") {
                $.modalConfirm(content, function (res) {
                    if (res) {
                        $.submitForm({
                            url: "/ProductManage/Order/SendOrder",
                            param: { orderId: Id },
                            success: function (json) {
                                $.currentWindow().$("#gridList").trigger("reloadGrid");
                            }
                        });
                    }
                });
            }
        }
        else if (state == "2") {
            $(".jqgrow").each(function (index) {
                var tds = $(this).find("td");
                if (tds.eq(1).text() == Id) {
                    content += "确认发货？<br />";
                    content += "订单号：<span style='color:red'>" + tds.eq(2).text() + "</span><br />";
                    content += "收货人：<span style='color:red'>" + tds.eq(3).text() + "</span><br />";
                    content += "联系电话：<span style='color:red'>" + tds.eq(4).text() + "</span><br />";
                    content += "收货地址：<span style='color:red'>" + tds.eq(5).text() + "</span><br />";
                    content += "备注：<span style='color:red'>" + tds.eq(10).text() + "</span><br />";
                    //content += "请确认会员【" + tds.eq(3).text() + "】已经支付订单【" + tds.eq(2).text() + "】的<span style='color:red'>【" + tds.eq(7).text() + "】</span>元！";
                    return;
                }
            });
            if (content != "") {
                $.modalConfirm(content, function (res) {
                    if (res) {
                        $.submitForm({
                            url: "/ProductManage/Order/FHOrder",
                            param: { orderId: Id },
                            success: function (json) {
                                $.currentWindow().$("#gridList").trigger("reloadGrid");
                            }
                        });
                    }
                });
            }
        }
        else if (state == "3") {
            $(".jqgrow").each(function (index) {
                var tds = $(this).find("td");
                if (tds.eq(1).text() == Id) {
                    content += "确认完成？<br />";
                    content += "订单号：<span style='color:red'>" + tds.eq(2).text() + "</span><br />";
                    //content += "请确认会员【" + tds.eq(3).text() + "】已经支付订单【" + tds.eq(2).text() + "】的<span style='color:red'>【" + tds.eq(7).text() + "】</span>元！";
                    return;
                }
            });
            if (content != "") {
                $.modalConfirm(content, function (res) {
                    if (res) {
                        $.submitForm({
                            url: "/ProductManage/Order/OverOrder",
                            param: { orderId: Id },
                            success: function (json) {
                                $.currentWindow().$("#gridList").trigger("reloadGrid");
                            }
                        });
                    }
                });
            }
        }
        else {
            $.submitForm({
                url: "/ProductManage/Order/SendOrder",
                param: { orderId: Id },
                success: function (json) {
                    $.currentWindow().$("#gridList").trigger("reloadGrid");
                }
            });
        }
    }

    //作废订单
    function btn_zf(Id) {
        var content = "";
        $(".jqgrow").each(function (index) {
            var tds = $(this).find("td");
            if (tds.eq(1).text() == Id) {
                content += "确认作废订单号为<span style='color:red'>【" + tds.eq(2).text() + "】</span>的订单吗？";
                return;
            }
        });
        if (content != "") {
            $.modalConfirm(content, function (res) {
                if (res) {
                    $.submitForm({
                        url: "/ProductManage/Order/ZFOrder",
                        param: { orderId: Id },
                        success: function (json) {
                            $.currentWindow().$("#gridList").trigger("reloadGrid");
                        }
                    });
                }
            });
        }
    }



    function getSelectIds() {
        var rows = $("#gridList").jqGridRowValue();
        var ids = $.map(rows, function (item, idx) {
            return "'" + item.F_Id + "'";
        }).join(',');
        return ids;
    }
</script>

<div class="topPanel">
    <div class="search">
        <table>
            <tr>
                <td>
                    <div class="input-group">
                        <input id="txt_keyword" type="text" class="form-control" placeholder="订单号" style="width: 200px;" />
                        <input id="txt_rName" type="text" class="form-control" placeholder="收货人" style="width: 200px; margin-left: 10px; margin-right: 10px" />
                        <input id="txt_startDate" type="text" class="form-control input-wdatepicker" onfocus="WdatePicker()" placeholder="下单日期" style="width: 150px;" />
                        --
                        <span style="float: right; margin-left: 3px;">
                            <input id="txt_endDate" type="text" class="form-control input-wdatepicker" onfocus="WdatePicker()" placeholder="下单日期" style="width: 150px;" />
                        </span>
                        <span class="input-group-btn">
                            <button id="btn_search" type="button" class="btn  btn-primary" title="搜索">
                                <i class="fa fa-search"></i>
                            </button>
                        </span>
                    </div>
                </td>
            </tr>
        </table>
    </div>
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>
        @*<div class="btn-group">
                <a id="NF-add" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_add()"><i class="fa fa-plus"></i>创建订单</a>
            </div>
            <div class="operate">
                    <ul class="nav nav-pills">
                        <li class="first">已选中<span>1</span>项</li>
                        <li><a id="NF-edit" authorize="yes" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>修改商品</a></li>
                        <li><a id="NF-delete" authorize="yes" onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除商品</a></li>
                        <li><a id="NF-Details" authorize="yes" onclick="btn_details()"><i class="fa fa-search-plus"></i>查看商品</a></li>
                        <li class="split"></li>
                        <li><a id="NF-InStock" onclick="btn_InStock()"><i class="fa fa-play-circle"></i>批量上架</a></li>
                        <li><a id="NF-outStock" onclick="btn_outStock()"><i class="fa fa-stop-circle"></i>批量下架</a></li>
                    </ul>
                    <a href="javascript:;" class="close"></a>
                </div>*@
        <!-- <script>$('.toolbar').authorizeButton()</script>-->
    </div>

</div>
<div class="tab-content content">
    <ul class="nav nav-tabs" role="tablist" id="ulOrder">
        <li role="presentation" class="active">
            <a href="#home" type="-3" id="ahome" aria-controls="home" role="tab" data-toggle="tab">全部订单</a>
        </li>
        <li role="presentation">
            <a href="#home" type="0" aria-controls="profile" role="tab" data-toggle="tab">未支付</a>
        </li>
        <li role="presentation">
            <a href="#home" type="1" aria-controls="profile" role="tab" data-toggle="tab">待发货</a>
        </li>
        <li role="presentation">
            <a href="#home" type="2" aria-controls="profile" role="tab" data-toggle="tab">待处理</a>
        </li>
        <li role="presentation">
            <a href="#home" type="3" aria-controls="profile" role="tab" data-toggle="tab">已完成</a>
        </li>
        <li role="presentation">
            <a href="#home" type="-1" aria-controls="profile" role="tab" data-toggle="tab">已取消</a>
        </li>
        <li role="presentation">
            <a href="#home" type="-2" aria-controls="profile" role="tab" data-toggle="tab">已作废</a>
        </li>
    </ul>
    <div role="tabpanel" class="tab-pane active " id="home">
        <div class="gridPanel tab-pane fade in active" id="baseInfo">
            <table id="gridList"></table>
            <div id="gridPager"></div>
        </div>
    </div>
</div>
